<?php
class Finance_func
{
	public function __construct()
	{
		$this->obj =& get_instance();
	}
	public function addFinance($orderInfo,$userInfo=null)
	{
		$tb_order_data = array(
							'user_id'=>$userInfo['id'],
							'order_number'=>$orderInfo['order_number'],
							'order_name'=>$orderInfo['order_name'],
							'order_prince'=>$orderInfo['prince'],
							'is_ok'=>$orderInfo['is_ok'],
							'out_time'=>time(),
		);
		$this->obj->db->insert('tb_order',$tb_order_data);

		$adduser_data = ($orderInfo['is_ok'] == 0)?array('lock_fund'=>$userInfo['lock_fund']*1+$orderInfo['prince']):array('fund'=>$userInfo['fund']*1+$orderInfo['prince']);
		$this->obj->db->where('user_id',$userInfo['id']);
		$this->obj->db->update('adduser',$adduser_data);

		$this->obj->Record_model->addRecord('addFinance',$orderInfo,$userInfo);
	}
	public function shoping($data)
	{
		$adduser_data['fund'] = $this->obj->userInfo['fund']*1-$data;
		$this->obj->db->where('user_id',$this->obj->userInfo['id']);
		$this->obj->db->update('adduser',$adduser_data);
		return $this->obj->db->affected_rows();
	}
	public function pass_finance($data)
	{
		$this->obj->db->select('adduser.fund,adduser.lock_fund,user.id,user.user');
		$this->obj->db->join('adduser','user.id=adduser.user_id');
		$this->obj->db->where('user.user',$data['post_name']);
		$userData = $this->obj->db->get('user')->result_array();
		$sqlData['fund'] = $userData[0]['fund']*1+$data['prince']*1;
		$this->obj->db->where('user_id',$userData['0']['id']);
		$this->obj->db->update('adduser',$sqlData);
		return $userData[0];
	}
}
?>